package com.atguigu.userprofile.dao

import com.atguigu.userprofile.bean.TagInfo
import com.atguigu.userprofile.util.MySqlUtil

object TagDAO {

  def getTagInfo(taskId:String):  TagInfo  ={
    val sql=s"""select id,tag_code,tag_name,
               | parent_tag_id,tag_type,tag_value_type,
               | tag_value_limit,tag_task_id,tag_comment,
               | create_time
               | from tag_info
               | where tag_task_id=$taskId""".stripMargin
      //或有对象   key->hashmap --> Option[value] ->1 Some[value] .get  -->2 None
     val tagInfoOpt: Option[TagInfo] = MySqlUtil.queryOne(sql,classOf[TagInfo],true)
     if(tagInfoOpt==None){
       throw  new RuntimeException("error :  no tag for this task_id:"+taskId)
     }else{
       tagInfoOpt.get
     }

  }

  // 查询所有 需要合并的标签
  //1 3级标签
  //2  有设定任务
  //3 任务为开启状态
  //select * from tag_info tg join task_info tk on tg.tag_task_id=tk.id where  tag_level =3 and  tk.status='1'
  def  getTagInfoOnTaskList(): List[TagInfo] ={
    val sql=
      s"""select  tg.id,tag_code,tag_name,parent_tag_id,tag_type,tag_value_type,tag_value_limit,tag_task_id,tag_comment,tg.create_time
         |    from tag_info tg join task_info tk  on tg.tag_task_id=tk.id  where tk.task_status='1'
       """.stripMargin

    println(sql)
     val tagList: List[TagInfo] = MySqlUtil.queryList(sql,classOf[TagInfo],true)
     tagList
  }

}
